package responsibility.dependenceInversiion.demo_02;

public class Demo02 {

    public static void main(String[] args) {
        Person person = new Person();

        person.receive(new Email());
        person.receive(new WeChat());
    }
}

// 完成 Person 接收消息的功能

// 方式2
// Person 类一旦仅仅依赖于抽象的接口, 后续扩展 消息类时就不需要改动Person了

class Person {
    public void receive(IReceiver receiver) {
        String info = receiver.getInfo();
        System.out.println(info);
    }
}

interface IReceiver {
    String getInfo();
}

class Email implements IReceiver{

    @Override
    public String getInfo() {
        return "info from email";
    }
}

class WeChat implements IReceiver{

    @Override
    public String getInfo() {
        return "info from wechat";
    }
}
